package com.hust360.percent.pojo;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hust360.percent.PercentApplication;

import android.annotation.SuppressLint;
import android.database.Cursor;

/**
 * 操作Shop实体的接口
 */
@SuppressLint("SimpleDateFormat")
public class ShopLocal extends Shop {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1865819415310202949L;
	static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

	@Override
	public List<Discount> getDiscountInfos() {
		Map<String, String> map = new HashMap<String, String>();
		map.put(Discount.SHOP_ID, id + "");
		return PercentApplication.discountDAO.findWithMap(map);
	}

	@Override
	public Long getLiked() {
		Cursor c;
		synchronized (PercentApplication.localDB) {
			c = PercentApplication.localDB.rawQuery(
					"SELECT * FROM liked WHERE shopId='" + id + "'", null);
		}
		long count = c.getCount();
		c.close();
		return count;
	}

	@Override
	public boolean isLiked(User user) {
		Cursor c;
		synchronized (PercentApplication.localDB) {
			c = PercentApplication.localDB.rawQuery(
					"SELECT * FROM liked WHERE uid='" + user.id
							+ "' AND shopId='" + id + "'", null);
		}
		int count = c.getCount();
		c.close();
		return count == 0 ? false : true;
	}

}
